let interstitialAd = null;
let videoAd = null;
export const $interstitialAd = {
	init: (ad_id) => {
		if (uni.createInterstitialAd) {
			interstitialAd = uni.createInterstitialAd({ adUnitId: ad_id })
			interstitialAd.onLoad(() => {
				console.log('onLoad event emit')
			})
			interstitialAd.onError((err) => {
				console.log('onError event emit', err)
			})
			interstitialAd.onClose((res) => {
				console.log('onClose event emit', res)
			})
		} 
	},

	show: () => {
		if (interstitialAd) {
			interstitialAd.show().catch((err) => {
				console.error('插屏广告显示失败', err)
			})
		}
	}

}

export const $videoAd = {
	init: (ad_id,e) => {
		if (uni.createRewardedVideoAd) {
			videoAd = uni.createRewardedVideoAd({
				adUnitId: ad_id
			})
			videoAd.onLoad(() => {})
			videoAd.onError((err) => {
				console.error('激励视频光告加载失败', err)
			})
			videoAd.onClose((status) => {
				e(status)
				
			})
		}
	},
	show: () => {
		if (videoAd) {
			videoAd.show().catch(() => {
				videoAd.load()
					.then(() => videoAd.show())
					.catch(err => {
						console.error('激励视频 广告显示失败', err)
					})
			})
		}
	}
}